const joi = require("joi");
const multiparty = require("multiparty")

module.exports = {
    path: '/a/upload',
    method: 'post',
    config: {
        handler: async (request, h)=> {
            const hapi = request.payload.a.hapi
            const readStream = request.payload.a
            const writeSteam = require("fs").createWriteStream(`./${hapi.filename}`);
            readStream.pipe(writeSteam);
            const hapib = request.payload.b.hapi
            const readStreamb = request.payload.b
            const writeSteamb = require("fs").createWriteStream(`./${hapib.filename}`);
            readStreamb.pipe(writeSteamb);
            return h.response({
                code : 1
            })
        },
        validate: {
            payload: {
                a: joi.any().meta({swaggerType: 'file'})
                .description("json file"),
                b: joi.any().meta({swaggerType: 'file'})
                .description("json file"),
            }
        },
        plugins: {
            'hapi-swagger': {
                payloadType: 'form'
            }
        },
        payload: {
            maxBytes: 1048576,
            parse: true,
            output: 'stream',
        },
        response: {
            schema: joi.object({
                code: joi.number().description("状态码")
            })
        },
        tags: ['api'],
        notes: '上传文件',
        description: "上传文件"
    }
}